﻿Imports OMANE.Common
Imports OMANE.Common.UI
Imports System.Collections.ObjectModel
Imports OMANE.Modules.TauxGarantis.ViewModels
Imports OMANE.Common.UI.Theme
Imports PTIC_GestionBDD
Imports OMANE.Common.Model.Interfaces
Imports Microsoft.Practices.Prism.Commands

''' <summary>
''' Module taux garanti
''' </summary>
''' <remarks></remarks>
Public Class ModuleTauxGaranti
    Implements IModule

    Private _dic As New Windows.ResourceDictionary()
    Private _CorrespEncoursValides As Boolean = False

    Friend Shared _app As Application

    Friend Shared currentasyncinfo As AsynchronousOperationInfo
    ''' <summary> 
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public ReadOnly Property Dependencies As System.Collections.Generic.IEnumerable(Of Common.ModuleReference) Implements Common.IModule.Dependencies
        Get
            Return Nothing
        End Get
    End Property

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub Load() Implements Common.IModule.Load
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub Reset(ByVal Application As Common.Application) Implements Common.IModule.Reset
        _app = Application

        Dim uiservice As IUIService = _app.GetService(Of IUIService)()
        Dim ModelOMANE As IModelOMANE = _app.GetService(Of IModelOMANE)()

        'Création du modèle du taux garanti à partir du modèle OMANE

        _dic.Source = New Uri("/OMANE.Modules.TauxGarantis;component/Ressources.xaml", System.UriKind.Relative)
        uiservice.ViewModelMainMenu.Children.Add(_dic("MainMenu"))
        'uiservice.ViewModelMainMenu.Tool.Children.Add(dic("ToolMainMenu"))
        Dim accmenu As V2ViewModelAccordeonMenuItem = _dic("AccordeonMenu")

        resetProcessViewer()
        resetEncours()
        resetParametrage()
        resetResulats()
        accmenu.Body.Root.Icone = StandardIcons.CHART_ORGANISATION

        uiservice.V2ViewModelAccordeonMenu.Etudes.Body.Root.Children.Add(accmenu.Body.Root)
        resetTarification(_dic)

        Dim dicTemplate = New Windows.ResourceDictionary()
        dicTemplate.Source = New Uri("/OMANE.Modules.TauxGarantis;component/RessourcesTemplate.xaml", System.UriKind.Relative)
        _app.GetService(Of IUIService)().AddResourceDictionary(dicTemplate)

        For Each corresp As Correspondance In Locator.ModelStatic.ListeTraitements.TraitTbleEncours.ListeChampsSortie.Values
            AddHandler corresp.EtatChanged, AddressOf ImportEncoursEtatChamps_Changed
        Next

        'Ajouter un évènement pour intercepter un changement d'implémentation du moteur 1
        AddHandler Locator.ModelStatic.ListeTraitements.MoteurMethodeEqTarifBeforeChanged, AddressOf OnMoteurMethode1BeforeChanged
        AddHandler Locator.ModelStatic.ListeTraitements.MoteurMethodeEqTarifChanged, AddressOf OnMoteurMethode1Changed

        AddHandler Locator.ModelStatic.ListeTraitements.TraitTbleEncours.FichierBDD_NomCompletChanged, AddressOf NomFichierEncoursChanged
        AddHandler Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.scenarioCentral.EtatCalculChanged, AddressOf ScenarioCentralMoteur2_EtatCalculAChange

        AddHandlersMoteur1()
    End Sub

    Private Sub OnMoteurMethode1Changed()
        AddHandlersMoteur1()
        'Mettre à jour les éléments à modifier lors d'un changement d'état
    End Sub
    Private Sub OnMoteurMethode1BeforeChanged()
        RemoveHandlersMoteur1()
    End Sub

    Public Sub AddHandlersMoteur1()
        AddHandler Locator.ModelStatic.ListeTraitements.TraitMoteurMethode1.EtatCalculScenCentralChanged, AddressOf ScenarioCentralMoteur1_EtatCalculAChange
    End Sub
    Public Sub RemoveHandlersMoteur1()
        RemoveHandler Locator.ModelStatic.ListeTraitements.TraitMoteurMethode1.EtatCalculScenCentralChanged, AddressOf ScenarioCentralMoteur1_EtatCalculAChange
    End Sub

    Private Sub ImportEncoursEtatChamps_Changed(ByVal sender As Object, ByVal e As EventArgs)
        Dim correspOK As Boolean = True
        For Each c As PTIC_GestionBDD.Correspondance In Locator.ModelStatic.ListeTraitements.TraitTbleEncours.ListeChampsSortie.Values
            If c.etat <> Drawing.Color.Green Then correspOK = False
        Next
        _CorrespEncoursValides = correspOK
        resetEncours()
        resetParametrage()
        resetResulats()
        'If correspOK Then
        '    Locator.ModelStatic.Univers.listeTraitements.TraitReqSegmentation.Calculer_DataTable()
        '    Dim t As DataTable = Locator.ModelStatic.Univers.listeTraitements.TraitReqSegmentation.DataTableResultat
        'End If
    End Sub
    Private Sub NomFichierEncoursChanged(ByVal sender As Object, ByVal e As EventArgs)
        resetEncours()
    End Sub

#Region "Affichage ProcessViewer"

    'Groupe d'onglets
    Private _ProcViewerTabs As New ObservableCollection(Of IViewModelTabSection)
    'Private _VMProcViewer As New ViewModelTraitementsViewer With {.Title = "TRAITEMENTS", .Icone = StandardIcons.PAGE_2}

    'Arborescence
    '.TabGroup groupe d'onglets activé par le noeud
    '.TabSection onlget affiché lors d'un clic sur le noeud
    '  Private _ProcViewer As New V2ViewModelTabGroup() With {.Title = "Traitements", .TabGroup = _ProcViewerTabs, .TabSection = _VMProcViewer}

    Private Sub resetProcessViewer()

        'If Not _ProcViewerTabs.Contains(_VMProcViewer) Then _ProcViewerTabs.Add(_VMProcViewer)
        'If Not _ProcViewer.Children.Contains( Then
        ' Dim accmenu As V2ViewModelAccordeonMenuItem = _dic("AccordeonMenu")
        '   If Not accmenu.Body(0).Children.Contains(_ProcViewer) Then accmenu.Body(0).Children.Add(_ProcViewer)

    End Sub

#End Region

#Region "Affichage Import et qualification de la table d'encours"
    Private _ImportTabs As New ObservableCollection(Of IViewModelTabSection)
    Private _VMImport As New ViewModelCmdEncoursImport With {.Title = "IMPORT", .Icone = StandardIcons.PAGE_2}
    Private _VMCorrespondances As New ViewModelCmdEncoursCorresp With {.Title = "CORRESPONDANCES", .Icone = StandardIcons.GRID}
    Private _VMRetraitements As New ViewModelCmdEncoursRetrait With {.Title = "RETRAITEMENTS", .Icone = StandardIcons.DRAWER}
    Private _VMStats As New ViewModelCmdEncoursStats With {.Title = "STATISTIQUES", .Icone = StandardIcons.CHART_BAR}

    Private _Import As New V2ViewModelTabGroup() With {.Title = "Fichier d'encours", .TabGroup = _ImportTabs, .TabSection = _VMImport}
    Private _FichierImport As New V2ViewModelTabGroup With {.Title = "Import", .TabGroup = _ImportTabs, .TabSection = _VMImport, .Icone = StandardIcons.PAGE_2}
    Private _Corresp As New V2ViewModelTabGroup With {.Title = "Correspondances", .TabGroup = _ImportTabs, .TabSection = _VMCorrespondances, .Icone = StandardIcons.GRID}
    Private _Retrait As New V2ViewModelTabGroup With {.Title = "Retraitements", .TabGroup = _ImportTabs, .TabSection = _VMRetraitements, .Icone = StandardIcons.DRAWER}
    Private _Stats As New V2ViewModelTabGroup With {.Title = "Statistiques", .TabGroup = _ImportTabs, .TabSection = _VMStats, .Icone = StandardIcons.CHART_BAR}


    Private Sub resetEncours()

        If Not _ImportTabs.Contains(_VMImport) Then _ImportTabs.Add(_VMImport)
        If Not _Import.Children.Contains(_FichierImport) Then _Import.Children.Add(_FichierImport)
        If _Import.Icone Is Nothing Then _Import.Icone = StandardIcons.ARROW_RIGHT

        Dim accmenu As V2ViewModelAccordeonMenuItem = _dic("AccordeonMenu")
        If Not accmenu.Body(0).Children.Contains(_Import) Then accmenu.Body(0).Children.Add(_Import)

        Dim TraitTbleEncours As PTIC_GestionBDD.tableBDD = Locator.ModelStatic.ListeTraitements.TraitTbleEncours
        If TraitTbleEncours.FichierBDD.NomComplet <> "" Then
            If Not _ImportTabs.Contains(_VMCorrespondances) Then _ImportTabs.Add(_VMCorrespondances)
            If Not _Import.Children.Contains(_Corresp) Then _Import.Children.Add(_Corresp)

            If _CorrespEncoursValides Then
                If Not _ImportTabs.Contains(_VMRetraitements) Then _ImportTabs.Add(_VMRetraitements)
                If Not _ImportTabs.Contains(_VMStats) Then _ImportTabs.Add(_VMStats)
                If Not _Import.Children.Contains(_Retrait) Then _Import.Children.Add(_Retrait)
                If Not _Import.Children.Contains(_Stats) Then _Import.Children.Add(_Stats)
            Else
                If _ImportTabs.Contains(_VMRetraitements) Then _ImportTabs.Remove(_VMRetraitements)
                If _ImportTabs.Contains(_VMStats) Then _ImportTabs.Remove(_VMStats)
                If _Import.Children.Contains(_Retrait) Then _Import.Children.Remove(_Retrait)
                If _Import.Children.Contains(_Stats) Then _Import.Children.Remove(_Stats)
            End If
        Else
            'Afficher les onglets s'ils n'existent pas déjà
            If _ImportTabs.Contains(_VMCorrespondances) Then _ImportTabs.Remove(_VMCorrespondances)
            If _ImportTabs.Contains(_VMRetraitements) Then _ImportTabs.Remove(_VMRetraitements)
            If _ImportTabs.Contains(_VMStats) Then _ImportTabs.Remove(_VMStats)
            If _Import.Children.Contains(_Corresp) Then _Import.Children.Remove(_Corresp)
            If _Import.Children.Contains(_Retrait) Then _Import.Children.Remove(_Retrait)
            If _Import.Children.Contains(_Stats) Then _Import.Children.Remove(_Stats)
        End If
    End Sub
#End Region

#Region "Affichage du paramétrage (segmentation et paramétrage technique)"

    Private _ParametresTabs As New ObservableCollection(Of IViewModelTabSection)
    Private _VMSegSelection As New ViewModelSegSelection With {.Title = "SEGMENTATION", .Icone = StandardIcons.BUILDINGS}
    Private _VMMethodeCalcul As New ViewModelMethodeDeCalcul With {.Title = "METHODE DE CALCUL", .Icone = StandardIcons.CALCULATOR}
    Private _VMDonneesEco As New ViewModelDonneesEconomiques With {.Title = "DONNEES ECONOMIQUES", .Icone = StandardIcons.BLOG}
    Private _VMDCPTIA As New ViewModelGarantiesDecesPtia With {.Title = "GARANTIES DECES/PTIA", .Icone = StandardIcons.SCRIPT}
    Private _VMINCAPINVAL As New ViewModelGarantiesIncapInval With {.Title = "GARANTIES INCAP/INVAL", .Icone = StandardIcons.APPLICATION2}
    Private _VMEstimateurs As New ViewModelEstimateurs With {.Title = "ESTIMATEURS", .Icone = StandardIcons.BRICKS}

    Private _Parametres As V2ViewModelTabGroup = New V2ViewModelTabGroup() With {.Title = "Paramètres", .TabGroup = _ParametresTabs, .TabSection = _VMSegSelection}
    Private _Selection As New V2ViewModelTabGroup With {.Title = "Segmentation", .TabGroup = _ParametresTabs, .TabSection = _VMSegSelection, .Icone = StandardIcons.BUILDINGS}
    Private _method As New V2ViewModelTabGroup With {.Title = "Methode de Calcul", .TabGroup = _ParametresTabs, .TabSection = _VMMethodeCalcul, .Icone = StandardIcons.CALCULATOR}
    Private _donneeseconomiques As New V2ViewModelTabGroup With {.Title = "Donnees Economiques", .TabGroup = _ParametresTabs, .TabSection = _VMDonneesEco, .Icone = StandardIcons.BLOG}
    Private _garantiesdeces As New V2ViewModelTabGroup With {.Title = "Garanties Deces / PTIA", .TabGroup = _ParametresTabs, .TabSection = _VMDCPTIA, .Icone = StandardIcons.SCRIPT}
    Private _garantiesincapacite As New V2ViewModelTabGroup With {.Title = "Garanties Incapacités / Invalidités", .TabGroup = _ParametresTabs, .TabSection = _VMINCAPINVAL, .Icone = StandardIcons.APPLICATION2}
    Private _estimateurs As New V2ViewModelTabGroup With {.Title = "Estimateurs", .TabGroup = _ParametresTabs, .TabSection = _VMEstimateurs, .Icone = StandardIcons.BRICKS}

    Private Sub resetParametrage()

        Dim accmenu As V2ViewModelAccordeonMenuItem = _dic("AccordeonMenu")

        If _CorrespEncoursValides Then
            If Not _ParametresTabs.Contains(_VMSegSelection) Then _ParametresTabs.Add(_VMSegSelection)
            If Not _ParametresTabs.Contains(_VMMethodeCalcul) Then _ParametresTabs.Add(_VMMethodeCalcul)
            If Not _ParametresTabs.Contains(_VMDonneesEco) Then _ParametresTabs.Add(_VMDonneesEco)
            If Not _ParametresTabs.Contains(_VMDCPTIA) Then _ParametresTabs.Add(_VMDCPTIA)
            If Not _ParametresTabs.Contains(_VMINCAPINVAL) Then _ParametresTabs.Add(_VMINCAPINVAL)
            If Not _ParametresTabs.Contains(_VMEstimateurs) Then _ParametresTabs.Add(_VMEstimateurs)

            If Not _Parametres.Children.Contains(_Selection) Then _Parametres.Children.Add(_Selection)
            If Not _Parametres.Children.Contains(_method) Then _Parametres.Children.Add(_method)
            If Not _Parametres.Children.Contains(_donneeseconomiques) Then _Parametres.Children.Add(_donneeseconomiques)
            If Not _Parametres.Children.Contains(_garantiesdeces) Then _Parametres.Children.Add(_garantiesdeces)
            If Not _Parametres.Children.Contains(_garantiesincapacite) Then _Parametres.Children.Add(_garantiesincapacite)
            If Not _Parametres.Children.Contains(_estimateurs) Then _Parametres.Children.Add(_estimateurs)

            If _Parametres.Icone Is Nothing Then _Parametres.Icone = StandardIcons.RULER_TRIANGLE
            If Not accmenu.Body(0).Children.Contains(_Parametres) Then
                Dim indexEncours As Integer = accmenu.Body(0).Children.IndexOf(_Import)
                accmenu.Body(0).Children.Insert(indexEncours + 1, _Parametres)
            End If

        Else
            If _ParametresTabs.Contains(_VMSegSelection) Then _ParametresTabs.Remove(_VMSegSelection)
            If _ParametresTabs.Contains(_VMMethodeCalcul) Then _ParametresTabs.Remove(_VMMethodeCalcul)
            If _ParametresTabs.Contains(_VMDonneesEco) Then _ParametresTabs.Remove(_VMDonneesEco)
            If _ParametresTabs.Contains(_VMDCPTIA) Then _ParametresTabs.Remove(_VMDCPTIA)
            If _ParametresTabs.Contains(_VMINCAPINVAL) Then _ParametresTabs.Remove(_VMINCAPINVAL)
            If _ParametresTabs.Contains(_VMEstimateurs) Then _ParametresTabs.Remove(_VMEstimateurs)

            If _Parametres.Children.Contains(_Selection) Then _Parametres.Children.Remove(_Selection)
            If _Parametres.Children.Contains(_method) Then _Parametres.Children.Remove(_method)
            If _Parametres.Children.Contains(_donneeseconomiques) Then _Parametres.Children.Remove(_donneeseconomiques)
            If _Parametres.Children.Contains(_garantiesdeces) Then _Parametres.Children.Remove(_garantiesdeces)
            If _Parametres.Children.Contains(_garantiesincapacite) Then _Parametres.Children.Remove(_garantiesincapacite)
            If _Parametres.Children.Contains(_estimateurs) Then _Parametres.Children.Remove(_estimateurs)

            If accmenu.Body(0).Children.Contains(_Parametres) Then accmenu.Body(0).Children.Remove(_Parametres)
        End If

    End Sub
#End Region

#Region "Affichage des résultats"
    Private _Resultats As New V2ViewModelTabGroup With {.Title = "Résultats", .Icone = StandardIcons.TRAFFIC}
    Private Sub resetResulats()
        Dim accmenu As V2ViewModelAccordeonMenuItem = _dic("AccordeonMenu")
        If _CorrespEncoursValides Then
            If Not accmenu.Body.Root.Children.Contains(_Resultats) Then
                Dim indexParam As Integer = accmenu.Body(0).Children.IndexOf(_Parametres)
                accmenu.Body.Root.Children.Insert(indexParam + 1, _Resultats)
            End If
            resetResutltatsEqTarifaire(_Resultats)
            resetResultatsProjComptes(_Resultats)
        Else
            If accmenu.Body.Root.Children.Contains(_Resultats) Then accmenu.Body.Root.Children.Remove(_Resultats)
            'resetResutltatsEqTarifaire(_Resultats)
            'resetResultatsProjComptes(_Resultats)
        End If
    End Sub
#End Region

#Region "Affichage résultats équilibre tarifaire"
    Private _resultatEqTarifairetabs As New ObservableCollection(Of IViewModelTabSection)
    Private _VMResEqTarifScenCent As New ViewModelScenarioCentral With {.Title = "SCENARIO SCENTRAL", .Icone = StandardIcons.TRAFFIC}
    Private _VMResEqTarifCalcDet As New ViewModelCalculsDetailles With {.Title = "CALCULS DETAILLES", .Icone = StandardIcons.CHART_CURVE}
    Private _VMResEqTarifSens As New ViewModelSensibilites With {.Title = "SENSIBILITES", .Icone = StandardIcons.VECTOR}
    Private _VMResEqTarifStressTests As New ViewModelStressTests With {.Title = "STRESS TESTS", .Icone = StandardIcons.CHART_LINE}
    Private _VMResEqTarifSynthese As New ViewModelSynthese With {.Title = "SYNTHESE", .Icone = StandardIcons.COMPASS}

    Private _resultatEqTarif As V2ViewModelTabGroup = New V2ViewModelTabGroup() With {.Title = "Résultats équilibre tarifaire", .TabGroup = _resultatEqTarifairetabs, .TabSection = _VMResEqTarifScenCent, .Icone = StandardIcons.CHART_LINE}
    Private _ResultEqTarifScenarioCentral As V2ViewModelTabGroup = New V2ViewModelTabGroup With {.Title = "Scénario central", .TabGroup = _resultatEqTarifairetabs, .TabSection = _VMResEqTarifScenCent, .Icone = StandardIcons.TRAFFIC}
    Private _ResultEqTarifcalculdetailles As V2ViewModelTabGroup = New V2ViewModelTabGroup With {.Title = "Calculs détaillés", .TabGroup = _resultatEqTarifairetabs, .TabSection = _VMResEqTarifCalcDet, .Icone = StandardIcons.CHART_CURVE}
    Private _ResultEqTarifsensibilites As V2ViewModelTabGroup = New V2ViewModelTabGroup With {.Title = "Sensibilités", .TabGroup = _resultatEqTarifairetabs, .TabSection = _VMResEqTarifSens, .Icone = StandardIcons.VECTOR}
    Private _ResultEqTarifstresstest As V2ViewModelTabGroup = New V2ViewModelTabGroup With {.Title = "Stress-Test", .TabGroup = _resultatEqTarifairetabs, .TabSection = _VMResEqTarifStressTests, .Icone = StandardIcons.CHART_LINE}
    Private _ResultEqTarifsynthese As V2ViewModelTabGroup = New V2ViewModelTabGroup With {.Title = "Synthèse", .TabGroup = _resultatEqTarifairetabs, .TabSection = _VMResEqTarifSynthese, .Icone = StandardIcons.COMPASS}

    Private Sub resetResutltatsEqTarifaire(ByVal parent As V2ViewModelTabGroup)
        If Not _resultatEqTarifairetabs.Contains(_VMResEqTarifScenCent) Then _resultatEqTarifairetabs.Add(_VMResEqTarifScenCent)
        If Not _resultatEqTarif.Children.Contains(_ResultEqTarifScenarioCentral) Then _resultatEqTarif.Children.Add(_ResultEqTarifScenarioCentral)
        If Not parent.Children.Contains(_resultatEqTarif) Then parent.Children.Add(_resultatEqTarif)
    End Sub

    Private Sub AfficheResultatsDetaillesEqTarif()
        _resultatEqTarifairetabs.Add(_VMResEqTarifCalcDet)
        _resultatEqTarifairetabs.Add(_VMResEqTarifSens)
        _resultatEqTarifairetabs.Add(_VMResEqTarifStressTests)
        _resultatEqTarifairetabs.Add(_VMResEqTarifSynthese)

        _resultatEqTarif.Children.Add(_ResultEqTarifcalculdetailles)
        _resultatEqTarif.Children.Add(_ResultEqTarifsensibilites)
        _resultatEqTarif.Children.Add(_ResultEqTarifstresstest)
        _resultatEqTarif.Children.Add(_ResultEqTarifsynthese)

        'Rafraichir les ViewModels (pour supprimer les valeurs des précédents calculs)
    End Sub
    Private Sub MasqueResultatsDetaillesEqTarif()
        _resultatEqTarifairetabs.Remove(_VMResEqTarifCalcDet)
        _resultatEqTarifairetabs.Remove(_VMResEqTarifSens)
        _resultatEqTarifairetabs.Remove(_VMResEqTarifStressTests)
        _resultatEqTarifairetabs.Remove(_VMResEqTarifSynthese)

        _resultatEqTarif.Children.Remove(_ResultEqTarifcalculdetailles)
        _resultatEqTarif.Children.Remove(_ResultEqTarifsensibilites)
        _resultatEqTarif.Children.Remove(_ResultEqTarifstresstest)
        _resultatEqTarif.Children.Remove(_ResultEqTarifsynthese)

        'Rafraichir les ViewModels (pour supprimer les valeurs des précédents calculs)
    End Sub

    Private Sub ScenarioCentralMoteur1_EtatCalculAChange(ByVal sender As Object, ByVal e As EventArgs)
        Dim moteur As moteurTauxGaranti1.IIntegMoteur_MethodeEqTarif = DirectCast(sender, moteurTauxGaranti1.IIntegMoteur_MethodeEqTarif)
        If moteur.etatCalculScenCentral = PTIC_Util.ValueEtatCalcul.A_JOUR Then
            AfficheResultatsDetaillesEqTarif()
        Else
            MasqueResultatsDetaillesEqTarif()
            _VMResEqTarifScenCent.refresh()
        End If
    End Sub
#End Region

#Region "Affichage résultats projection des comptes"
    Private _resultats_ProjComptes_tabs As New ObservableCollection(Of IViewModelTabSection)
    Private _VMResProjTxGarScenCent = New ViewModelScenarioCentralModel2 With {.Title = "SCENARIO CENTRAL", .Icone = StandardIcons.TRAFFIC}
    Private _VMResProjTxGarTbleTrav = New ViewModelTableTravail With {.Title = "TABLE DE TRAVAIL", .Icone = StandardIcons.TRAFFIC}
    Private _VMResProjTxGarCalcDet = New ViewModelCalculsDetaillesModel2 With {.Title = "CALCULS DETAILLES", .Icone = StandardIcons.CHART_CURVE}
    Private _VMResProjTxGarResCRT = New ViewModelResCRT With {.Title = "Comptes de résultat".ToUpper(), .Icone = StandardIcons.CHART_LINE}
    Private _VMResProjTxGarGraphs = New ViewModelGraphModelProjection With {.Title = "GRAPHIQUES", .Icone = StandardIcons.VECTOR}

    Private _resultats_ProjComptes As V2ViewModelTabGroup = New V2ViewModelTabGroup() With {.Title = "Résultats projection des comptes", .TabGroup = _resultats_ProjComptes_tabs, .TabSection = _VMResProjTxGarScenCent, .Icone = StandardIcons.CHART_LINE}
    Private _resScenCentModele2 As New V2ViewModelTabGroup With {.Title = "Scenario central", .TabGroup = _resultats_ProjComptes_tabs, .TabSection = _VMResProjTxGarScenCent, .Icone = StandardIcons.TRAFFIC}
    Private _resTableTravailModele2 As New V2ViewModelTabGroup With {.Title = "Table de travail", .TabGroup = _resultats_ProjComptes_tabs, .TabSection = _VMResProjTxGarTbleTrav, .Icone = StandardIcons.TRAFFIC}
    Private _resCalculsDetModele2 As New V2ViewModelTabGroup With {.Title = "Calculs détaillés", .TabGroup = _resultats_ProjComptes_tabs, .TabSection = _VMResProjTxGarCalcDet, .Icone = StandardIcons.CHART_CURVE}
    Private _resResCRTModele2 As New V2ViewModelTabGroup With {.Title = "Comptes de résultat", .TabGroup = _resultats_ProjComptes_tabs, .TabSection = _VMResProjTxGarResCRT, .Icone = StandardIcons.CHART_LINE}
    Private _resGraphModelProjection As New V2ViewModelTabGroup With {.Title = "Graphiques", .TabGroup = _resultats_ProjComptes_tabs, .TabSection = _VMResProjTxGarGraphs, .Icone = StandardIcons.VECTOR}


    Private _simulations_tabs As New ObservableCollection(Of IViewModelTabSection)
    Private _VMSimulations As New ViewModelSimulation With {.Title = "SIMULATION", .Icone = StandardIcons.TRAFFIC}
    Private _Simulation As New V2ViewModelTabGroup With {.Title = "Simulations", .TabGroup = _resultats_ProjComptes_tabs, .TabSection = _VMSimulations, .Icone = StandardIcons.TRAFFIC}

    Private Sub resetResultatsProjComptes(ByVal parent As V2ViewModelTabGroup)

        If Not _resultats_ProjComptes_tabs.Contains(_VMResProjTxGarScenCent) Then _resultats_ProjComptes_tabs.Add(_VMResProjTxGarScenCent)
        If Not _resultats_ProjComptes.Children.Contains(_resScenCentModele2) Then _resultats_ProjComptes.Children.Add(_resScenCentModele2)
        If Not parent.Children.Contains(_resultats_ProjComptes) Then parent.Children.Add(_resultats_ProjComptes)
        'If Not _resultats_ProjComptes_tabs.Contains(_VMSimulations) Then _resultats_ProjComptes_tabs.Add(_VMSimulations)
        _VMSimulations.SetOwner(_resultats_ProjComptes_tabs)
    End Sub

    Private Sub AfficheResDetaillesProjComptes()
        _resultats_ProjComptes_tabs.Add(_VMResProjTxGarTbleTrav)
        _resultats_ProjComptes_tabs.Add(_VMResProjTxGarCalcDet)
        _resultats_ProjComptes_tabs.Add(_VMResProjTxGarResCRT)
        _resultats_ProjComptes_tabs.Add(_VMResProjTxGarGraphs)
        _resultats_ProjComptes_tabs.Add(_VMSimulations)

        _resultats_ProjComptes.Children.Add(_resTableTravailModele2)
        _resultats_ProjComptes.Children.Add(_resCalculsDetModele2)
        _resultats_ProjComptes.Children.Add(_resResCRTModele2)
        _resultats_ProjComptes.Children.Add(_resGraphModelProjection)
        _resultats_ProjComptes.Children.Add(_Simulation)
    End Sub
    Private Sub MasqueResDetaillesProjComptes()
        _resultats_ProjComptes_tabs.Remove(_VMResProjTxGarTbleTrav)
        _resultats_ProjComptes_tabs.Remove(_VMResProjTxGarCalcDet)
        _resultats_ProjComptes_tabs.Remove(_VMResProjTxGarResCRT)
        _resultats_ProjComptes_tabs.Remove(_VMResProjTxGarGraphs)
        _resultats_ProjComptes_tabs.Remove(_VMSimulations)

        _resultats_ProjComptes.Children.Remove(_resTableTravailModele2)
        _resultats_ProjComptes.Children.Remove(_resCalculsDetModele2)
        _resultats_ProjComptes.Children.Remove(_resResCRTModele2)
        _resultats_ProjComptes.Children.Remove(_resGraphModelProjection)
        _resultats_ProjComptes.Children.Remove(_Simulation)
    End Sub
    Private Sub ScenarioCentralMoteur2_EtatCalculAChange(ByVal sender As Object, ByVal e As EventArgs)
        Dim moteur As moteurTauxGaranti2.scenarioCentralMoteur2 = DirectCast(sender, moteurTauxGaranti2.scenarioCentralMoteur2)
        If moteur.EtatCalcul = PTIC_Util.ValueEtatCalcul.A_JOUR Then
            AfficheResDetaillesProjComptes()
        Else
            MasqueResDetaillesProjComptes()
        End If
    End Sub
#End Region

    Private Sub resetTarification(ByVal dic As Windows.ResourceDictionary)
        Dim tariftabs As New ObservableCollection(Of IViewModelTabSection)
        tariftabs.Add(New ViewModelTarif With {.Title = "ECHEANCIER", .Icone = StandardIcons.TRAFFIC})

        Dim echeancier As New V2ViewModelTabGroup With {.Title = "Echéancier", .TabGroup = tariftabs, .TabSection = tariftabs(0), .Icone = StandardIcons.TRAFFIC}
        Dim tarification As V2ViewModelTabGroup = New V2ViewModelTabGroup() With {.Title = "Tarification", .TabGroup = tariftabs, .TabSection = tariftabs(0), .Icone = StandardIcons.CHART_LINE}
        tarification.Children.Add(echeancier)
        Dim uiservice As IUIService = _app.GetService(Of IUIService)()
        'uiservice.V2ViewModelAccordeonMenu.Etudes
        uiservice.V2ViewModelAccordeonMenu.Etudes.Body.Root.Children.Add(tarification)


        'accmenu.Body(0).Children.Add(tarification)
    End Sub

    Private Sub resetyyTEST(ByVal dic As Windows.ResourceDictionary)
        Dim accmenu As V2ViewModelAccordeonMenuItem = dic("AccordeonMenu")
        Dim teststabs As New ObservableCollection(Of IViewModelTabSection)
        teststabs.Add(New ViewModelScenarioCentralModel2 With {.Title = "SCENARIO CENTRAL", .Icone = StandardIcons.TRAFFIC})
        teststabs.Add(New ViewModelCalculsDetaillesModel2 With {.Title = "CALCULS DETAILLES", .Icone = StandardIcons.TRAFFIC})
        teststabs.Add(New ViewModelTableTravail With {.Title = "TABLE DE TRAVAIL", .Icone = StandardIcons.TRAFFIC})
        teststabs.Add(New ViewModelSimulation With {.Title = "SIMULATION", .Icone = StandardIcons.TRAFFIC})
        teststabs.Add(New ViewModelSimulationResult With {.Title = "RESULTAT DE LA SIMULATION", .Icone = StandardIcons.TRAFFIC})
        teststabs.Add(New ViewModelGraphModelProjection With {.Title = "GRAPHIQUES", .Icone = StandardIcons.TRAFFIC})

        Dim testnode As New V2ViewModelTabGroup With {.Title = "Test Node Please Ignore", .TabGroup = teststabs, .TabSection = Nothing, .Icone = StandardIcons.TRAFFIC}
        'Dim tarification As V2ViewModelTabGroup = New V2ViewModelTabGroup() With {.Title = "Tarification", .TabGroup = tariftabs, .TabSection = tariftabs(0), .Icone = StandardIcons.CHART_LINE}
        'tarification.Children.Add(echeancier)

        accmenu.Body(0).Children.Add(testnode)
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub Unload() Implements Common.IModule.Unload
        'MsgBox("Déchargement du module taux garantis")
        'Récupérer le modèle dans le locator
        'Lancer la méthode de déchargements
        Locator.ModelStatic.Connection.Dispose()
    End Sub


    Private Shared _AProposCommand As New DelegateCommand(Of Object)(AddressOf AProposExecute, AddressOf AProposCanExecute)
    Private Shared OMANEPeoples As String() = _
        New String() { _
          "PIERRE TISSOT", _
          "THIERRY TAILLANDIER", _
          "ISMAEL OBEY", _
          "ERIC VACHEZ", _
          "CEDRIC LAILLER"}

    Public Shared ReadOnly Property AProposCommand As DelegateCommand(Of Object)
        Get
            Return _AProposCommand
        End Get
    End Property
    Private Shared Sub AProposExecute(ByVal parameter As Object)
        Dim ui = _app.GetService(Of IUIService)()
        ui.ShowMessage("Ce module a été construit par le village corse de Natixis assisté par les hommes de mains de Vivei" & _
                       vbCrLf & _
                       String.Join(vbCrLf, OMANEPeoples))
    End Sub
    Private Shared Function AProposCanExecute(ByVal parameter As Object) As Boolean
        Return True
    End Function


End Class

<ServiceInfo(LifeTime:=ServiceLifetime.Singleton, Name:="CorrespondanceService")> _
Public Interface ICorrespondanceService

End Interface